wayland: Set gtk-decoration-layout
authorFlorian Müllner <fmuellner@gnome.org>
Thu, 5 Jun 2014 13:30:16 +0000 (15:30 +0200)
committerFlorian Müllner <fmuellner@gnome.org>
Fri, 6 Jun 2014 13:32:59 +0000 (15:32 +0200)
Pick up the setting from the org.gnome.desktop.wm.preferences schema
if available. It is slightly more involved than other settings, as
the actual button names used in the schema differ from the ones we
use, so we need an additional translation step.

https://bugzilla.gnome.org/show_bug.cgi?id=731273

gdk/wayland/Makefile.am
gdk/wayland/gdkscreen-wayland.c
gdk/wayland/wm-button-layout-translation.c [new file with mode: 0644]
gdk/wayland/wm-button-layout-translation.h [new file with mode: 0644]

index 98e849a7e216e58991496c7ff44001572a090a59..356fd281f2cfe0441fb9f0fc59b71353dac0f7bf 100644 (file)
@@ -44,7 +44,9 @@ libgdk_wayland_la_SOURCES =                   \
        gdkselection-wayland.c                  \
        gdkwindow-wayland.c                     \
        gdkwayland.h                            \
-       gdkprivate-wayland.h
+       gdkprivate-wayland.h                    \
+       wm-button-layout-translation.c          \
+       wm-button-layout-translation.h
 
 libgdkinclude_HEADERS =                                \
        gdkwayland.h
index 7e3dfe5f22d2663e163c53e8fed9c09d51280fb1..261ac20167bbdaa667e910e0c94b7c960770eecc 100644 (file)
@@ -29,6 +29,8 @@
 #include "gdkwayland.h"
 #include "gdkprivate-wayland.h"
 
+#include "wm-button-layout-translation.h"
+
 typedef struct _GdkWaylandScreen      GdkWaylandScreen;
 typedef struct _GdkWaylandScreenClass GdkWaylandScreenClass;
 
@@ -511,6 +513,7 @@ static TranslationEntry translations[] = {
   { "org.gnome.desktop.sound", "input-feedback-sounds", "gtk-enable-input-feedback-sounds", G_TYPE_BOOLEAN, { . b = FALSE } },
   { "org.gnome.desktop.privacy", "recent-files-max-age", "gtk-recent-files-max-age", G_TYPE_INT, { .i = 30 } },
   { "org.gnome.desktop.privacy", "remember-recent-files",    "gtk-recent-files-enabled", G_TYPE_BOOLEAN, { .b = TRUE } },
+  { "org.gnome.desktop.wm.preferences", "button-layout",    "gtk-decoration-layout", G_TYPE_STRING, { .s = "menu:close" } },
   { "org.gnome.settings-daemon.plugins.xsettings", "antialiasing", "gtk-xft-antialias", G_TYPE_NONE, { .i = 0 } },
   { "org.gnome.settings-daemon.plugins.xsettings", "hinting", "gtk-xft-hinting", G_TYPE_NONE, { .i = 0 } },
   { "org.gnome.settings-daemon.plugins.xsettings", "hinting", "gtk-xft-hintstyle", G_TYPE_NONE, { .i = 0 } },
@@ -681,6 +684,31 @@ set_value_from_entry (GdkScreen        *screen,
     }
 }
 
+static void
+set_decoration_layout_from_entry (GdkScreen        *screen,
+                                  TranslationEntry *entry,
+                                  GValue           *value)
+{
+  GdkWaylandScreen *screen_wayland = GDK_WAYLAND_SCREEN (screen);
+  GSettings *settings;
+
+  settings = (GSettings *)g_hash_table_lookup (screen_wayland->settings, entry->schema);
+
+  if (settings)
+    {
+      gchar *s = g_settings_get_string (settings, entry->key);
+
+      translate_wm_button_layout_to_gtk (s);
+      g_value_set_string (value, s);
+
+      g_free (s);
+    }
+  else
+    {
+      g_value_set_static_string (value, entry->fallback.s);
+    }
+}
+
 static gboolean
 set_capability_setting (GdkScreen                 *screen,
                        GValue                    *value,
@@ -705,7 +733,10 @@ gdk_wayland_screen_get_setting (GdkScreen   *screen,
   entry = find_translation_entry_by_setting (name);
   if (entry != NULL)
     {
-      set_value_from_entry (screen, entry, value);
+      if (strcmp (name, "gtk-decoration-layout") == 0)
+        set_decoration_layout_from_entry (screen, entry, value);
+      else
+        set_value_from_entry (screen, entry, value);
       return TRUE;
    }
 
diff --git a/gdk/wayland/wm-button-layout-translation.c b/gdk/wayland/wm-button-layout-translation.c
new file mode 100644 (file)
index 0000000..0fa4d2c
--- /dev/null
@@ -0,0 +1,88 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2014 Red Hat, Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see <http://www.gnu.org/licenses/>.
+ *
+ * Author:  Florian Müllner <fmuellner@gnome.org>
+ */
+
+#include <stdio.h>
+#include <string.h>
+#include <glib.h>
+
+#include "wm-button-layout-translation.h"
+
+static void
+translate_buttons (char *layout, int *len_p)
+{
+  char *strp = layout, *button;
+  int len = 0;
+
+  if (!layout || !*layout)
+    goto out;
+
+  while ((button = strsep (&strp, ",")))
+    {
+      char *gtkbutton;
+
+      if (strcmp (button, "menu") == 0)
+        gtkbutton = "icon";
+      else if (strcmp (button, "appmenu") == 0)
+        gtkbutton = "menu";
+      else if (strcmp (button, "minimize") == 0)
+        gtkbutton = "minimize";
+      else if (strcmp (button, "maximize") == 0)
+        gtkbutton = "maximize";
+      else if  (strcmp (button, "close") == 0)
+        gtkbutton = "close";
+      else
+        continue;
+
+      if (len)
+        layout[len++] = ',';
+
+      strcpy (layout + len, gtkbutton);
+      len += strlen (gtkbutton);
+    }
+  layout[len] = '\0';
+
+out:
+  if (len_p)
+    *len_p = len;
+}
+
+void
+translate_wm_button_layout_to_gtk (char *layout)
+{
+  char *strp = layout, *left_buttons, *right_buttons;
+  int left_len, right_len = 0;
+
+  left_buttons = strsep (&strp, ":");
+  right_buttons = strp;
+
+  translate_buttons (left_buttons, &left_len);
+  memmove (layout, left_buttons, left_len);
+
+  if (strp == NULL)
+    goto out; /* no ":" in layout */
+
+  layout[left_len++] = ':';
+
+  translate_buttons (right_buttons, &right_len);
+  memmove (layout + left_len, right_buttons, right_len);
+
+out:
+  layout[left_len + right_len] = '\0';
+}
diff --git a/gdk/wayland/wm-button-layout-translation.h b/gdk/wayland/wm-button-layout-translation.h
new file mode 100644 (file)
index 0000000..87210b6
--- /dev/null
@@ -0,0 +1,26 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2014 Red Hat, Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see <http://www.gnu.org/licenses/>.
+ *
+ * Author:  Florian Müllner <fmuellner@gnome.org>
+ */
+
+#ifndef __WM_BUTTON_LAYOUT_TRANSLATION__
+#define __WM_BUTTON_LAYOUT_TRANSLATION__
+
+void translate_wm_button_layout_to_gtk (char *layout);
+
+#endif